package cn.jee.jsp;

import cn.jee.jsp.util.JdbcUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;
@WebServlet("/editClazz")
public class EditClazzServlet  extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req,resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String clazz_id = req.getParameter("clazz_id");
    //select,一条数据
    String sql="select * from clazz where id=?";
    Object[] args={clazz_id};
    String[] cols={"id","name"};
    List<String[]> res=JdbcUtil.query(sql,args,cols);
    String[] row=res.get(0);
    HttpSession session=req.getSession();
    session.setAttribute("clazz",row);
    resp.sendRedirect(req.getContextPath()+"/clazz_edit.jsp");
  }
}
